package item.inkcloud.userservice.service;


import item.inkcloud.userservice.entity.UserInfo;
import item.inkcloud.userservice.mapper.UserMapper;
import item.inkcloud.userservice.feignService.DistributionService;
import item.inkcloud.userservice.pojo.ProvinceHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ChangeProvinceService {

    @Autowired
    UserMapper userMapper;

    @Autowired
    ProvinceHandler provinceHandler;


    @Autowired
    DistributionService distributionService;

    public int changeProvince(String userId, String province){

        String newProvince = provinceHandler.handleProvince(province);


        try {
            UserInfo info = userMapper.findInfoById(userId);

            String oldProvince = info.getProvince();

            userMapper.changeUserProvince(userId,newProvince);

            int status =    distributionService.exchangeProvince(oldProvince,newProvince);

            return status;
        }catch (Exception e){
            System.out.println("eee");
            return 0;
        }



    }



}
